package com.ziyuan.controller;

import com.ziyuan.pojo.Category;
import com.ziyuan.pojo.Result;
import com.ziyuan.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @PostMapping
    public Result add(@RequestBody @Validated(Category.add.class) Category category){
        categoryService.add(category);
        return Result.success();

    }
    @GetMapping
    public Result<List<Category>> GET(){
        List<Category> category = categoryService.get();
        return Result.success(category);
    }
    @GetMapping("/detail")
    public Result findById(Integer id){
        Category category = categoryService.findById(id);
        return Result.success(category);

    }
    @PutMapping
    public Result PutCategory(@RequestBody @Validated(Category.update.class) Category category){
        categoryService.PutCategory(category);
        return Result.success();
    }
    @DeleteMapping
    public Result Delete(Integer id){
        categoryService.delete(id);
        return Result.success();
    }
//    再来一次测试提交
}
